<div class="page-content" >
	<div class="panel panel-default">
		 
		<div class="panel-body">
			<form id="myform" method="post"  class="form-horizontal" action="<{:addons_url('doSendMaterial')}>">
				<input type="hidden" name="id" value="<{$data.id}>">
				<div class="form-group">
					<label for="input-title" class="col-sm-2 control-label">用户数量</label>
					<div class="col-sm-7 mgt8">
						共<{:count($openids)}>个用户
					</div>
				</div>

				<div class="form-group">
					<label for="input-title" class="col-sm-2 control-label">素材信息</label>
					<div class="col-sm-5 mgt8">
					 <input type="hidden" name="keyName" value="">
						 <span id="show_text"></span><a target="select_material"  data-type="modal" href="/BoxAddon/Wechat/Feeds/index/select/1" class="btn btn-primary btn-xs ">选择素材</a>
					</div>
					 
				</div>
				 
				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-7">
						<a id="sendMaterialBtn" onclick="sendMaterial(this)" class="btn btn-primary">发送</a>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>

<script>
 var t2 ;
 function sendMaterial(_this){
 	var keyName=$("[name='keyName']").val();
  	  if(!keyName){
  	  	 hiApp.alert("请先选择素材");
  	  	 return false;
  	  }
 	  var _this=$("#sendMaterialBtn");
  	  $(_this).attr("disabled","disabled");
  	  $(_this).removeAttr("onclick");
  	  $(_this).text("发送中...");

  	  $.get("/BoxAddon/Wechat/Feeds/doSendMaterial",{keyName:keyName},function(data){
  	  	 t2 = window.setInterval("getSendMsg()",1000); 
  	  })

 }

function getSendMsg(){
	$.get("/BoxAddon/Wechat/Feeds/getSendMsg",function(data){
  	  	  if(data==1){
  	  	  	window.clearInterval(t2); 
  	  	  	$("#sendMaterialBtn").text("发送完成");
  	  	  }else{
  	  	  	$("#sendMaterialBtn").text("发送中:".data);
  	  	  }
  	  })
}

$(function(){
  $(document).on("select_material",function(e,data){
  	  $("#user_select_material").modal("hide");
  	  $("#show_text").text(data.title+"("+data.keyName+")");
  	  $("[name='keyName']").val(data.keyName);
  })



});
 </script>
